package com.etc;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @author yuanshushu
 * @date 2018/9/1
 * @description SESSION控制类
 */
@RestController
public class SessionController {
 
    @GetMapping("/test")
    public Map<String, Object> testSessionId(HttpServletRequest request) {
 
        Map<String, Object> sessionIdPortMap = new HashMap<String, Object>();
 
        // 获取session信息
        sessionIdPortMap.put("sessionId：", request.getSession().getId());
        sessionIdPortMap.put("服务器端口：", request.getServerPort());
 
        // 获取session中uid为1的用户的信息
        String user_1 = (String) request.getSession().getAttribute("user_1");
        sessionIdPortMap.put("user_1", user_1);
 
        return sessionIdPortMap;
    }
 
}